/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package baiwa.rta.dao.mapping;

import baiwa.rta.model.RMcphdrModel;
import baiwa.rta.model.TowerModel;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

/**
 *
 * @author jirapatjantsakool
 */
public class ComplaintMapping implements RowMapper<RMcphdrModel> {

    public RMcphdrModel mapRow(ResultSet rs, int line) throws SQLException {
        ResultSetExtractor<RMcphdrModel> extractor = new ResultSetExtractor<RMcphdrModel>() {
            public RMcphdrModel extractData(ResultSet rs) throws SQLException, DataAccessException {
                
                RMcphdrModel model = new RMcphdrModel();
                model.setCphid(rs.getInt("CPHID"));
                model.setCphdocno(rs.getString("CPHDOCNO"));
                model.setRlrmid(rs.getInt("RLRMID"));
                model.setCphdocstat(rs.getString("CPHDOCSTAT"));
                model.setCphreqby(rs.getString("CPHREQBY"));
                model.setCphcredat(rs.getDate("CPHREQDAT"));
                model.setCphreqtel(rs.getString("CPHREQTEL"));
                model.setCphreqemail(rs.getString("CPHREQEMAIL"));
                model.setCphrcvby(rs.getString("CPHRCVBY"));
                model.setCphrcvdat(rs.getDate("CPHRCVDAT"));
                model.setCphcreby(rs.getString("CPHCREBY"));
                model.setCphcredat(rs.getDate("CPHCREDAT"));
                model.setCphupdby(rs.getString("CPHUPDBY"));
                model.setCphupddat(rs.getDate("CPHUPDDAT"));

                 /* ---- Tower Data From Join Table------*/
                TowerModel tower = new TowerModel();
                tower.setTower(rs.getString("RLSTTOWER"));
                tower.setFloor(rs.getString("RLSTFLOOR"));
                tower.setUnitNo(rs.getString("RLSTUNITNO"));
                tower.setAddress(rs.getString("RLSTADDR"));
                model.setTower(tower);

                return model;
            }
        };
        return extractor.extractData(rs);
    }
}
